package cn.tedu.servlet;

import java.util.Map;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import javax.servlet.http.HttpServlet;

import cn.tedu.util.CommonValue;

/**
 * Servlet implementation class SysInitServlet
 */
public class SysInitServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SysInitServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
    public void init() throws ServletException {
    	ServletContext servletContext=this.getServletContext();
    	
    }
	/**
	 * @see Servlet#init(ServletConfig)
	 */
	public void init(ServletConfig config) throws ServletException {
		//用局部初始化读取信息
		/*
		String encoding=config.getInitParameter("encoding");
		String fileName=config.getInitParameter("propertyName");
		System.out.println(encoding+"   "+fileName);
		CommonValue.encoding=encoding;
		CommonValue.dbproperty=fileName;
		*/
		
		//用全局初始读取信息
		ServletContext servletContext=config.getServletContext();
		String encoding=servletContext.getInitParameter("globalEncoding");
		String fileName=servletContext.getInitParameter("globalPropertyName");
		System.out.println(encoding+"   "+fileName);
		CommonValue.encoding=encoding;
		CommonValue.dbproperty=fileName;
		
		Map<String,ServletRegistration> servlets=(Map<String,ServletRegistration>)servletContext.getServletRegistrations();
		System.out.println(servlets.size());
		for(String key: servlets.keySet()) {
			ServletRegistration sr=servlets.get(key);
			System.out.println(sr.getMappings()+"   "+sr.getClassName());
		}
	}

	/**
	 * @see Servlet#destroy()
	 */
	public void destroy() {
		// TODO Auto-generated method stub
	}

}
